﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Api.Shared.Model.Olaiya
{
    public class KxComplete
    {
        [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
        public int? Id { get; set; }

        [SugarColumn(IsNullable = true)]
        public string BoxNum { get; set; } = string.Empty;

        [SugarColumn(IsNullable = true)]
        public string DocNum { get; set; } = string.Empty;

        /// <summary>
        /// 托盘码
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string PalletNum { get; set; } = string.Empty;

        /// <summary>
        /// 工作站点位
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string DockCode { get; set; } = string.Empty;

        [SugarColumn(IsNullable = true)]
        public string SsccCode { get; set; } = string.Empty;

        /// <summary>
        /// 订单行号
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string LineNum { get; set; } = string.Empty;

        /// <summary>
        /// 物料编码
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string MaterialCode { get; set; } = string.Empty;

        /// <summary>
        /// 物料编码Int
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public short? MaterialCodeShort { get; set; }

        /// <summary>
        /// 批次
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string LotAttr { get; set; } = string.Empty;

        /// <summary>
        /// 订单数量
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public int Qty { get; set; }

        /// <summary>
        /// 有效期
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string? ExpiredDate { get; set; }

        /// <summary>
        /// 托盘状态
        /// </summary>

        [SugarColumn(IsNullable = true)]
        public string? PalletStatus { get; set; } = "1";

        [SugarColumn(IsNullable = true)]
        public string UserDef1 { get; set; } = string.Empty;

        [SugarColumn(IsNullable = true)]
        public string UserDef2 { get; set; } = string.Empty;

        [SugarColumn(IsNullable = true)]
        public string UserDef3 { get; set; } = string.Empty;

        public DateTime? ExpiredDateTime
        {
            get
            {
                // 添加备用格式：纯日期格式"yyyy-MM-dd"
                string[] formats = { "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd" };

                if (
                    DateTime.TryParseExact(
                        ExpiredDate,
                        formats,
                        CultureInfo.InvariantCulture,
                        DateTimeStyles.None,
                        out DateTime parsedDate
                    )
                )
                {
                    return parsedDate;
                }
                return DateTime.MinValue;
            }
        }

        [SugarColumn(IsNullable = true)]
        public DateTime? CreateTime { get; set; } = DateTime.Now;
    }
}
